
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>Adding new database styles &#8212; iprPy 0.10.2 documentation</title>
    <link rel="stylesheet" href="../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script crossorigin="anonymous" integrity="sha256-Ae2Vz/4ePdIu6ZyI/5ZGsYnb+m0JlOmKPjt6XZ9JJkA=" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
    <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["$", "$"], ["\\(", "\\)"]], "processEscapes": true, "ignoreClass": "document", "processClass": "math|output_area"}})</script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Calculation Styles" href="../calculation_styles.html" />
    <link rel="prev" title="Adding new buildcombos styles" href="addbuildcombos.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../calculation_styles.html" title="Calculation Styles"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="addbuildcombos.html" title="Adding new buildcombos styles"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">iprPy 0.10.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Extending iprPy</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="adding-new-database-styles">
<h1>Adding new database styles<a class="headerlink" href="#adding-new-database-styles" title="Permalink to this headline">¶</a></h1>
<p>The basic steps associated with implementing a new database style in iprPy are</p>
<ol class="arabic simple">
<li><p>Create a new subdirectory in iprPy/database named for the new database
style.</p></li>
<li><p>Create a file that defines the Database subclass.  Name the file
after the subclass name, typically by converting the style name to upper
camel case (each word capitalized with no separators).</p></li>
<li><p>Define the database subclass initialization function to handle any
style-specific parameters for accessing the database.</p></li>
<li><p>Define the methods for getting, adding, updating and deleting records and
tar archives to/from the database style.</p></li>
<li><p>Create an “__init__.py” file that imports the subclass.</p></li>
<li><p>Write documentation for the database style in the README.md file.</p></li>
</ol>
<div class="section" id="files-in-the-calculation-style-directories">
<h2>Files in the calculation style directories<a class="headerlink" href="#files-in-the-calculation-style-directories" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p><strong>[Style].py</strong>: Defines the Database subclass for the database style.
This defines how the iprPy codebase interacts with the database.</p></li>
<li><p><strong>README.md</strong>: Descriptions of what the database type is and what the
access parameters are.</p></li>
<li><p><strong>__init__.py</strong>: Allows Python to identify the database directory as
a sub-package and be able to import the database subclass into iprPy.</p></li>
</ul>
<div class="section" id="style-py">
<h3>[Style].py<a class="headerlink" href="#style-py" title="Permalink to this headline">¶</a></h3>
<p>The iprPy package interacts with the database style through the defined
Database subclass.  Considerable work has gone into making it easy to
define new subclass definitions by modifying values in pre-existing subclass
definitions.  This section describes the different components of defining a
Database subclass.</p>
<p>All of the high-throughput interaction functions are defined in the parent
class.  Only style-specific functions need to be defined for getting, adding,
updating and deleting stored records and calculation tar archives to/from the
database in the subclass.</p>
<div class="section" id="inheritance">
<h4>Inheritance<a class="headerlink" href="#inheritance" title="Permalink to this headline">¶</a></h4>
<p>The class should be a child of iprPy.database.Database.</p>
</div>
<div class="section" id="init">
<h4>__init__()<a class="headerlink" href="#init" title="Permalink to this headline">¶</a></h4>
<p>The __init__() function interprets any parameters needed to access a
database of the given type.  After establishing/defining a connection, the
parameters or objects to interact with the database are saved.  Finally, the
parent class’ __init__() method is called to set the database host name and
other common attributes.</p>
</div>
<div class="section" id="record-interaction-functions">
<h4>Record interaction functions<a class="headerlink" href="#record-interaction-functions" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li><p>get_records() returns a list of Record objects matching the conditions given.</p></li>
<li><p>get_record() returns a single Record object if exactly one uniquely matches
the conditions given.</p></li>
<li><p>get_records_df() returns a pandas.DataFrame in which the records matching the
conditions given are transformed into flat dictionaries and then collected
together.</p></li>
<li><p>add_record() adds a single record to the database.</p></li>
<li><p>update_record() updates a single record stored in the database.</p></li>
<li><p>delete_record() deletes a single record stored in the database.</p></li>
</ul>
</div>
<div class="section" id="archive-interaction-functions">
<h4>Archive interaction functions<a class="headerlink" href="#archive-interaction-functions" title="Permalink to this headline">¶</a></h4>
<ul class="simple">
<li><p>get_tar() returns a tarfile.TarFile object containing the archived
calculation folder content for a specific record.</p></li>
<li><p>add_tar() archives a calculation folder associated with a single record and
adds it to the database.</p></li>
<li><p>update_tar() updates the archived content for a single record stored in the
database.</p></li>
<li><p>delete_tar() deletes the archived content for a single record stored in the
database.</p></li>
</ul>
</div>
</div>
<div class="section" id="init-py">
<h3>__init__.py<a class="headerlink" href="#init-py" title="Permalink to this headline">¶</a></h3>
<p>The __init__.py file simply needs to tell Python to include the Database
subclass.  For instance, if the subclass is called “Style”, then
__init__.py contains</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">.Style</span> <span class="kn">import</span> <span class="n">Style</span>
<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;Style&#39;</span><span class="p">]</span>
</pre></div>
</div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Adding new database styles</a><ul>
<li><a class="reference internal" href="#files-in-the-calculation-style-directories">Files in the calculation style directories</a><ul>
<li><a class="reference internal" href="#style-py">[Style].py</a><ul>
<li><a class="reference internal" href="#inheritance">Inheritance</a></li>
<li><a class="reference internal" href="#init">__init__()</a></li>
<li><a class="reference internal" href="#record-interaction-functions">Record interaction functions</a></li>
<li><a class="reference internal" href="#archive-interaction-functions">Archive interaction functions</a></li>
</ul>
</li>
<li><a class="reference internal" href="#init-py">__init__.py</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="addbuildcombos.html"
                        title="previous chapter">Adding new buildcombos styles</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="../calculation_styles.html"
                        title="next chapter">Calculation Styles</a></p>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../calculation_styles.html" title="Calculation Styles"
             >next</a> |</li>
        <li class="right" >
          <a href="addbuildcombos.html" title="Adding new buildcombos styles"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">iprPy 0.10.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" >Extending iprPy</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.1.2.
    </div>
  </body>
</html>